#include "polar.h"

Polar::Polar(double a, double b)
{
    try
    {
        if ((a < 0) && ((b < 0) || (b > 360)))
        {
            throw "This is not polar coordinates!";
        }
        if (a < 0)
        {
            throw "Wrong radius!";
        }
        if ((b < 0) || (b > 360))
        {
            throw "Wrong angle!";
        }
        firstCoordinate = a;
        secondCoordinate = b;
    }
    catch (const char *str)
    {
        firstCoordinate = 0;
        secondCoordinate = 0;
        cout << str << endl;
    }
}

Polar::Polar() : Polar(0, 0)
{

}

void Polar::set(double a, double b)
{
    try
    {
        if ((a < 0) && ((b < 0) || (b > 360)))
        {
            throw "This is not polar coordinates!";
        }
        if (a < 0)
        {
            throw "Wrong radius!";
        }
        if ((b < 0) || (b > 360))
        {
            throw "Wrong angle!";
        }
        firstCoordinate = a;
        secondCoordinate = b;
    }
    catch (const char* str)
    {
        cout << str << endl ;
    }
}

Cartesian Polar::convertToCartesian()
{
    Cartesian tmp(firstCoordinate * cos(secondCoordinate * M_PI / 180),
        firstCoordinate * sin(secondCoordinate * M_PI / 180));
    return tmp;
}
